/*
 * @LastEditors: 杜康
 * @LastEditTime: 2021-10-01 16:28:35
 */
// 双端队列
class Deque {
    constructor () {
        this.count = 0
        this.lowestCount = 0
        this.items = {}
    }
    addFront (element) {
        if (this.isEmpty()) {
            return undefined
        } else if (this.lowestCount > 0) {
            this.lowestCount -= 1
            this.items[this.lowestCount] = element
        } else {
            for (let i = this.count; i > 0; i--) {
                this.items[i] = this.items[i - 1]
            }
            this.count += 1
            this.lowestCount = 0
            this.items[0] = element
        }
    }
    addBack (element) {
        this.items[this.count] = element
        this.count += 1
    }
    removeFront () { }
    removeBack () { }
    peekFront () { }
    peekBack () { }
    isEmpty () {
        return this.count - this.lowestCount === 0
    }
    size () {
        return this.count - this.lowestCount
    }
    clear () {
        this.items = {}
        this.lowestCount = 0
        this.count = 0
    }
    toString () {
        if (this.isEmpty()) {
            return ''
        }
        let objString = `${this.items[this.lowestCount]}`
        for (let i = this.lowestCount + 1; i < this.count; i++) {
            objString = `${objString},${this.items[i]}`
        }
        return objString
    }
}

const deque = new Deque()
deque.addFront('Mistic')
deque.addBack('Yuki')
deque.addFront('Milet')
console.log('🚀 ~ deque', deque)
